// pages/tabber/home/home.js
const request = require("../../../utils/request.js");
const imageCdn = "https://tdesign.gtimg.com/mobile/demos";
const swiperList = [];
Page({
  /**
   * 页面的初始数据
   */
  data: {
    current: 0,
    autoplay: true,
    duration: 500,
    interval: 1000,
    swiperList,
    visible: true,
    marquee1: {
      speed: 80,
      loop: -1,
      delay: 0,
    },
    img1: "https://tdesign.gtimg.com/mobile/demos/example1.png",
    img2: "https://tdesign.gtimg.com/mobile/demos/example2.png",
    img3: "https://tdesign.gtimg.com/mobile/demos/example3.png",
    // 宫格循环
    gridList: [
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
      {
        imgg: "/static/img/分类 (1).png",
        text: "分类名称",
        url: "/pages/tabber/list/list",
      },
    ],
    //商品列表
    goodsList: [
      {
        id: 1,
        im: "/static/img/sp.png",
        title: "咖啡机咖啡机1",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 2,
        im: "/static/img/sp2.png",
        title: "咖啡机咖啡机2",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 3,
        im: "/static/img/sp3.png",
        title: "咖啡机咖啡机3",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 4,
        im: "/static/img/sp4.png",
        title: "咖啡机咖啡机4",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
    ],
    swiperImg: "", // 轮播图
    noticeFont: "", // 公告文字
    gridbox:"", // 宫格
    goodslist:"", // 商品列表
  },

  methods: {},
  // 获取轮播图
  getswiperImg() {
    const _this = this;
    request.wxRequest(
      "banner/list",
      function (err, data) {
        // console.log(err, data)
        if (err) {
          // 失败；
        } else {
          _this.setData({
            swiperImg: data.data.image,
          });
        }
      },
      "GET",
      {
        id: 1,
      }
    );
  },
  // 公告
  getNotice() {
    const _this = this;
    request.wxRequest(
      "notice/list",
      function (err, data) {
        // console.log(err, data)
        if (err) {
          // 失败；
          console.error(err);
        } else {
          _this.setData({
            noticeFont: data.data.list,
          });
        }
      }
    )
  },
  // 宫格
  gridBox() {
    const _this = this;
    request.wxRequest(
      "menu/list1",
      function (err, data) {
        // console.log(err, data)
        if (err) {
          // 失败；
        } else {
          _this.setData({
            gridbox: data.data.list
          });
        }
      }
    )
  },
  // 商品列表
  getGoodsList() {
    const _this = this;
    request.wxRequest(
      "product/list1",
      function (err, data) {
        // console.log(err, data)
        if (err) {
          // 失败；
        } else {
          _this.setData({
            goodslist: data.data.list
          });
        }
      }
    )
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    // 获取轮播图
    this.getswiperImg();
    // 获取公告
    this.getNotice();
    // 获取宫格
    this.gridBox();
    // 获取商品列表
    this.getGoodsList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
